package com.pactera.madp.cp.controller.oms.marketing;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.common.log.annotation.SysLog;
import com.pactera.madp.cp.api.page.MarketingPage;
import com.pactera.madp.cp.api.vo.marketing.MarketingHotVO;
import com.pactera.madp.cp.common.util.PageUtil;
import com.pactera.madp.cp.service.MarketingHotService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: yuShen.qi
 * @Date: 2021/5/26 10:40
 * @Description:
 */
@RestController
@RequestMapping("/marketing-hot")
@Api(value = "marketingHot", tags = "营销素材-分类管理-热榜")
public class MarketingHotController {

    @Resource
    private MarketingHotService marketingHotService;

    /**
     * 得到素材打开次数和发送次数并分页
     *
     * @return
     */
   @GetMapping("/page")
   @ApiOperation(value = "得到素材打开次数和发送次数")
    public R<Page<MarketingHotVO>> getList(MarketingPage page,Integer hotState){
       List<MarketingHotVO> marketingHotVOS = marketingHotService.allList(hotState);
       return R.ok(PageUtil.split(marketingHotVOS,page.getPageCurrent(),page.getPageSize()));
   }

    /**
     * 通过类型获取素材的打开和发送次数
     *
     * @param type
     * @param page
     * @return
     */
    @GetMapping("/page-type")
    @ApiOperation(value = "通过类型获取素材的打开和发送次数")
    public R getListByType(@RequestParam(value = "type") Integer type,@RequestParam(value = "hotState") Integer hotState, MarketingPage page){
       List listByType = marketingHotService.getListByType(type,hotState);
     return R.ok(PageUtil.split(listByType,page.getPageCurrent(),page.getPageSize()));
    }

    /**
     * 保存列表信息并发布
     *
     * @return
     */
    @SysLog("营销素材-分类管理-热榜-保存列表信息并发布")
    @GetMapping("/release")
    @ApiOperation(value = "保存列表信息并发布！")
    public R saveAndRelease(@RequestParam(value = "hotState") Integer hotState){
        marketingHotService.saveAndRelease(hotState);
    return R.ok();
   }

}
